<template>
  <div>
    <div v-if="!custom" class="detailItem">
      <!-- <i class="iconfont" :style="{ color: oneColor ? '#4b8af4' : randomColor }" v-html="icon" /> -->
      <i class="iconfont" :style="{ color: '#4b8af4' }" v-html="icon" />
      <div class="label" v-html="label + '：'" />
      <div class="detail">
        <slot name="valueSlot">
          <el-link
            v-if="item.isFile && value!=='' && value!=='-' && value!=='/'"
            type="primary"
            @click="handleDownloadValidator(value)"
          >
            查看
          </el-link>
          <b v-else>{{ value }}</b>
        </slot>
      </div>
    </div>
    <div v-else class="customItem">
      <div class="topInner">
        <!-- <i class="iconfont" :style="{ color: oneColor ? '#4b8af4' : randomColor }" v-html="icon" /> -->
        <i class="iconfont" :style="{ color: '#4b8af4' }" v-html="icon" />
        <div v-html="label + '：'" />
      </div>
      <slot name="detail" />
    </div>
    <attachPopUp ref="attachPopUp" />
  </div>
</template>

<script>
import commonList from '@/assets/mixin/commonList'

export default {
  mixins: [commonList],
  props: {
    labelWidth: {
      type: Number,
      default: 240
    },
    custom: {
      type: Boolean,
      default: false
    },
    // icon: {
    //   type: String,
    //   default: '&#xe62c;'
    // },
    label: {
      type: String,
      default: '检查时间'
    },
    // oneColor: {
    //   type: Boolean,
    //   default: false
    // },
    value: {
      type: [String, Array, Number],
      default: ''
    },
    item: {
      type: Object,
      default: () => {
        return {
          isFile: false
        }
      }
    }
  },
  data() {
    return {
      icon: '&#xe62c;',
      colors: [
        '#4b8af4',
        '#17b5ff',
        '#07cdd4',
        '#fe961d',
        '#ff5b28',
        '#17b5ff',
        '#418dff'
      ]
    }
  },
  computed: {
    randomColor() {
      return this.colors[Math.floor(Math.random() * this.colors.length)]
    },
    randomTextColor() {
      const brightness = Math.floor(Math.random() * 256) // 0-255
      const textColor = brightness > 127 ? 'black' : 'white'
      return textColor
    }
  },
  methods: {
    handleDownloadValidator(item) {
      if (typeof item === 'string') {
        this.handleDownLoad(item)
      } else {
        this.openAttachPopUp(item)
      }
    }
  }
}
</script>

<style lang="scss" scoped>
.detailItem {
  width: 100%;
  min-height: 62px;
  // background-color: #e4e8ef7a;
  border-radius: 4px;
  display: flex;
  flex-direction: row;
  align-items: flex-start;
  justify-content: flex-start;
  margin: 8px 0;
  padding: 13px;
  flex-wrap: nowrap;
  border: 1px solid #eaf0f6;
  background: #eaf0f6;
  .iconfont {
    font-size: 22px;
    margin: 0 15px;
    line-height: 36px;
  }
  .label {
    height: 100%;
    font-family: MicrosoftYaHei;
    font-size: 24px;
    font-weight: normal;
    font-stretch: normal;
    line-height: 36px;
    letter-spacing: 0px;
    color: #07142e;
    // white-space: nowrap;
    max-width: 72%;
    white-space: nowrap;
  }
  .detail {
    flex: 1;
    overflow: hidden;
    display: flex;
    justify-content: flex-start;
    flex-wrap: wrap;
    font-size: 24px;
    line-height: 36px;
    word-break: break-all;
    span {
      font-size: 24px;
      word-break: break-all;
    }
  }
  b {
    width: 100%;
    word-break: break-word;
    font-family: MicrosoftYaHei;
    font-size: 24px;
    font-weight: normal;
    font-stretch: normal;
    line-height: 36px;
    letter-spacing: 0px;
    color: #07142e;
  }
}
.customItem {
  width: 100%;
  min-height: 62px;
  background-color: #e4e8ef7a;
  border-radius: 4px;
  margin: 8px 0;
  display: flex;
  flex-direction: column;
  .topInner {
    width: 100%;
    height: 62px;
    display: flex;
    align-items: center;
    justify-content: flex-start;
    .iconfont {
      font-size: 30px;
      margin: 0 15px;
    }
    .label {
      font-family: MicrosoftYaHei;
      font-size: 26px;
      font-weight: normal;
      font-stretch: normal;
      line-height: 36px;
      letter-spacing: 0px;
      color: #07142e;
      white-space: nowrap;
    }
    b {
      font-family: MicrosoftYaHei;
      font-size: 26px;
      font-weight: normal;
      font-stretch: normal;
      line-height: 36px;
      letter-spacing: 0px;
      color: #07142e;
    }
  }
}
</style>
